Skip to content

Fix readField during merge of objects sandwiched between circular objects. - #13084

Draft
phryneas wants to merge 1 commit into
release-4.1from
pr/merge-circular-objects-fix-readField
Draft

Fix readField during merge of objects sandwiched between circular objects.#13084
phryneas wants to merge 1 commit into
release-4.1from
pr/merge-circular-objects-fix-readField

Conversation

@phryneas

@phryneas phryneas commented Jan 7, 2026

Copy link
Copy Markdown
Member

See #9315 (comment) for the user reproduction.

The test for this uncovers additional problems that might be fixed later.

The general problem here is a situation where an incoming object has another normalized object both as a parent and child.

Parent:1.foo -> Child:2.bar -> Parent:1

So, in this case, the merge function for Parent runs before the merge for Child has a chance to run - and the readField function that would like to access properties of Child cannot read them from the store yet.

This doesn't happen for non-circular objects, since these are merged from incomingById in a leaf-to-root order, but in this circular case, leaf and root are the same object - so no matter which order they are merged in, a child will have unmerged fields.

I'm not happy with this solution, so putting it as draft for now. I'd be happy to feedback.

@changeset-bot

changeset-bot Bot commented Jan 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1ee5b01

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@phryneas
phryneas requested a review from jerelmiller January 7, 2026 15:46
@pkg-pr-new

pkg-pr-new Bot commented Jan 7, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@13084

commit: 1ee5b01

this.get(objectOrReference.__ref, storeFieldName)
: objectOrReference && objectOrReference[storeFieldName]
) as SafeReadonly<T>;
) as SafeReadonly<T> | undefined;

@phryneas phryneas Jan 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda unrelated, but it came up during the PR. getFieldValue<string> is a hidden cast to string, even though the function can always return undefined, too.

@apollo-librarian

apollo-librarian Bot commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 4 changed, 0 removed
* (developer-tools)/react/(latest)/caching/advanced-topics.mdx
* (developer-tools)/react/(latest)/caching/cache-field-behavior.mdx
* (developer-tools)/react/(latest)/data/fragments.mdx
* (developer-tools)/react/(latest)/data/mutations.mdx

Build ID: 6d765f1e679e779f48f96fb4
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/6d765f1e679e779f48f96fb4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant